package com.ktmall.ktmalluijava.utils;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/9 上午9:46
 */
@Setter
@Getter
public class Page <T>{
    private Integer pageNo;//当前页码
    private Integer pageSize;// 每页显示条数
    private Integer totalCount; //总记录数
    private Integer totalPageCount; //总页数
    private List<T> data; //分页数据

    public Page(){

    }

    public Page(Integer pageNo,Integer pageSize,Integer totalPageCount ,Integer totalCount , List<T> data){
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPageCount = totalPageCount;
        this.data = data;
    }

    public void setPageNo(Integer pageNo) {
        if(pageNo<1){
            pageNo = 1;
        }
        if(this.totalPageCount>0 && pageNo>this.totalPageCount){
            pageNo = this.totalPageCount;
        }
        this.pageNo = pageNo;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        this.totalPageCount=this.totalCount%this.pageSize==0?
                this.totalCount/this.pageSize:
                this.totalCount/this.pageSize+1;
    }


}
